<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="部门id" prop="deptId">
        <el-input
          v-model="queryParams.deptId"
          placeholder="请输入部门id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="图纸ID" prop="drawingId">
        <el-input
          v-model="queryParams.drawingId"
          placeholder="请输入图纸ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="线路ID" prop="lineId">
        <el-input
          v-model="queryParams.lineId"
          placeholder="请输入线路ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="线code" prop="lineCode">
        <el-input
          v-model="queryParams.lineCode"
          placeholder="请输入线code"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="火车型号ID" prop="trainModelId">
        <el-input
          v-model="queryParams.trainModelId"
          placeholder="请输入火车型号ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="图标ID" prop="iconId">
        <el-input
          v-model="queryParams.iconId"
          placeholder="请输入图标ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="火车状态" prop="trainStatus">
        <el-select v-model="queryParams.trainStatus" placeholder="请选择火车状态" clearable>
          <el-option
            v-for="dict in dict.type.biz_place_train_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="放置位置" prop="placement">
        <el-input
          v-model="queryParams.placement"
          placeholder="请输入放置位置"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="机车号" prop="trainNumber">
        <el-input
          v-model="queryParams.trainNumber"
          placeholder="请输入机车号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="乘务员ID" prop="crewId">
        <el-input
          v-model="queryParams.crewId"
          placeholder="请输入乘务员ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="乘务员工号" prop="crewWorkNumber">
        <el-input
          v-model="queryParams.crewWorkNumber"
          placeholder="请输入乘务员工号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="乘务员姓名" prop="crewName">
        <el-input
          v-model="queryParams.crewName"
          placeholder="请输入乘务员姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="确认员ID" prop="confirmerId">
        <el-input
          v-model="queryParams.confirmerId"
          placeholder="请输入确认员ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="确认员工号" prop="confirmerWorkNumber">
        <el-input
          v-model="queryParams.confirmerWorkNumber"
          placeholder="请输入确认员工号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="确认员姓名" prop="confirmerName">
        <el-input
          v-model="queryParams.confirmerName"
          placeholder="请输入确认员姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="入站时间" prop="entryTime">
        <el-date-picker clearable
          v-model="queryParams.entryTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择入站时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="审核通过时间" prop="approvalTime">
        <el-date-picker clearable
          v-model="queryParams.approvalTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择审核通过时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="预计离开时间" prop="estimatedDepartureTime">
        <el-date-picker clearable
          v-model="queryParams.estimatedDepartureTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择预计离开时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="当前审核人ID" prop="currentApproverId">
        <el-input
          v-model="queryParams.currentApproverId"
          placeholder="请输入当前审核人ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="当前审核人工号" prop="currentApproverWorkNumber">
        <el-input
          v-model="queryParams.currentApproverWorkNumber"
          placeholder="请输入当前审核人工号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="当前审核人姓名" prop="currentApproverName">
        <el-input
          v-model="queryParams.currentApproverName"
          placeholder="请输入当前审核人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:stockyard_train_position:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:stockyard_train_position:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:stockyard_train_position:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:stockyard_train_position:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="stockyard_train_positionList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="部门id" align="center" prop="deptId" />
      <el-table-column label="图纸ID" align="center" prop="drawingId" />
      <el-table-column label="线路ID" align="center" prop="lineId" />
      <el-table-column label="线code" align="center" prop="lineCode" />
      <el-table-column label="火车型号ID" align="center" prop="trainModelId" />
      <el-table-column label="图标ID" align="center" prop="iconId" />
      <el-table-column label="火车状态" align="center" prop="trainStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.biz_place_train_status" :value="scope.row.trainStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="放置位置" align="center" prop="placement" />
      <el-table-column label="机车号" align="center" prop="trainNumber" />
      <el-table-column label="乘务员ID" align="center" prop="crewId" />
      <el-table-column label="乘务员工号" align="center" prop="crewWorkNumber" />
      <el-table-column label="乘务员姓名" align="center" prop="crewName" />
      <el-table-column label="确认员ID" align="center" prop="confirmerId" />
      <el-table-column label="确认员工号" align="center" prop="confirmerWorkNumber" />
      <el-table-column label="确认员姓名" align="center" prop="confirmerName" />
      <el-table-column label="入站时间" align="center" prop="entryTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.entryTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核通过时间" align="center" prop="approvalTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.approvalTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="预计离开时间" align="center" prop="estimatedDepartureTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.estimatedDepartureTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="当前审核人ID" align="center" prop="currentApproverId" />
      <el-table-column label="当前审核人工号" align="center" prop="currentApproverWorkNumber" />
      <el-table-column label="当前审核人姓名" align="center" prop="currentApproverName" />
      <el-table-column label="描述信息" align="center" prop="description" />
      <el-table-column label="标准参数" align="center" prop="standardParams" />
      <el-table-column label="自定义参数" align="center" prop="customParams" />
      <el-table-column label="扩展信息" align="center" prop="ext" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:stockyard_train_position:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:stockyard_train_position:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改整备场火车位置信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="部门id" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入部门id" />
        </el-form-item>
        <el-form-item label="图纸ID" prop="drawingId">
          <el-input v-model="form.drawingId" placeholder="请输入图纸ID" />
        </el-form-item>
        <el-form-item label="线路ID" prop="lineId">
          <el-input v-model="form.lineId" placeholder="请输入线路ID" />
        </el-form-item>
        <el-form-item label="线code" prop="lineCode">
          <el-input v-model="form.lineCode" placeholder="请输入线code" />
        </el-form-item>
        <el-form-item label="火车型号ID" prop="trainModelId">
          <el-input v-model="form.trainModelId" placeholder="请输入火车型号ID" />
        </el-form-item>
        <el-form-item label="图标ID" prop="iconId">
          <el-input v-model="form.iconId" placeholder="请输入图标ID" />
        </el-form-item>
        <el-form-item label="火车状态" prop="trainStatus">
          <el-radio-group v-model="form.trainStatus">
            <el-radio
              v-for="dict in dict.type.biz_place_train_status"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="放置位置" prop="placement">
          <el-input v-model="form.placement" placeholder="请输入放置位置" />
        </el-form-item>
        <el-form-item label="机车号" prop="trainNumber">
          <el-input v-model="form.trainNumber" placeholder="请输入机车号" />
        </el-form-item>
        <el-form-item label="乘务员ID" prop="crewId">
          <el-input v-model="form.crewId" placeholder="请输入乘务员ID" />
        </el-form-item>
        <el-form-item label="乘务员工号" prop="crewWorkNumber">
          <el-input v-model="form.crewWorkNumber" placeholder="请输入乘务员工号" />
        </el-form-item>
        <el-form-item label="乘务员姓名" prop="crewName">
          <el-input v-model="form.crewName" placeholder="请输入乘务员姓名" />
        </el-form-item>
        <el-form-item label="确认员ID" prop="confirmerId">
          <el-input v-model="form.confirmerId" placeholder="请输入确认员ID" />
        </el-form-item>
        <el-form-item label="确认员工号" prop="confirmerWorkNumber">
          <el-input v-model="form.confirmerWorkNumber" placeholder="请输入确认员工号" />
        </el-form-item>
        <el-form-item label="确认员姓名" prop="confirmerName">
          <el-input v-model="form.confirmerName" placeholder="请输入确认员姓名" />
        </el-form-item>
        <el-form-item label="入站时间" prop="entryTime">
          <el-date-picker clearable
            v-model="form.entryTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择入站时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="审核通过时间" prop="approvalTime">
          <el-date-picker clearable
            v-model="form.approvalTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择审核通过时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="预计离开时间" prop="estimatedDepartureTime">
          <el-date-picker clearable
            v-model="form.estimatedDepartureTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择预计离开时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="当前审核人ID" prop="currentApproverId">
          <el-input v-model="form.currentApproverId" placeholder="请输入当前审核人ID" />
        </el-form-item>
        <el-form-item label="当前审核人工号" prop="currentApproverWorkNumber">
          <el-input v-model="form.currentApproverWorkNumber" placeholder="请输入当前审核人工号" />
        </el-form-item>
        <el-form-item label="当前审核人姓名" prop="currentApproverName">
          <el-input v-model="form.currentApproverName" placeholder="请输入当前审核人姓名" />
        </el-form-item>
        <el-form-item label="描述信息" prop="description">
          <el-input v-model="form.description" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="标准参数" prop="standardParams">
          <el-input v-model="form.standardParams" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="自定义参数" prop="customParams">
          <el-input v-model="form.customParams" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="扩展信息" prop="ext">
          <el-input v-model="form.ext" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listStockyard_train_position, getStockyard_train_position, delStockyard_train_position, addStockyard_train_position, updateStockyard_train_position } from "@/api/system/stockyard_train_position"

export default {
  name: "Stockyard_train_position",
  dicts: ['biz_place_train_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 整备场火车位置信息表格数据
      stockyard_train_positionList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        deptId: null,
        drawingId: null,
        lineId: null,
        lineCode: null,
        trainModelId: null,
        iconId: null,
        trainStatus: null,
        placement: null,
        trainNumber: null,
        crewId: null,
        crewWorkNumber: null,
        crewName: null,
        confirmerId: null,
        confirmerWorkNumber: null,
        confirmerName: null,
        entryTime: null,
        approvalTime: null,
        estimatedDepartureTime: null,
        currentApproverId: null,
        currentApproverWorkNumber: null,
        currentApproverName: null,
        description: null,
        standardParams: null,
        customParams: null,
        ext: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        createBy: [
          { required: true, message: "创建者不能为空", trigger: "blur" }
        ],
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        updateBy: [
          { required: true, message: "更新者不能为空", trigger: "blur" }
        ],
        updateTime: [
          { required: true, message: "更新时间不能为空", trigger: "blur" }
        ],
        deptId: [
          { required: true, message: "部门id不能为空", trigger: "blur" }
        ],
        drawingId: [
          { required: true, message: "图纸ID不能为空", trigger: "blur" }
        ],
        lineId: [
          { required: true, message: "线路ID不能为空", trigger: "blur" }
        ],
        lineCode: [
          { required: true, message: "线code不能为空", trigger: "blur" }
        ],
        trainModelId: [
          { required: true, message: "火车型号ID不能为空", trigger: "blur" }
        ],
        iconId: [
          { required: true, message: "图标ID不能为空", trigger: "blur" }
        ],
        trainStatus: [
          { required: true, message: "火车状态不能为空", trigger: "change" }
        ],
        placement: [
          { required: true, message: "放置位置不能为空", trigger: "blur" }
        ],
        trainNumber: [
          { required: true, message: "机车号不能为空", trigger: "blur" }
        ],
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询整备场火车位置信息列表 */
    getList() {
      this.loading = true
      listStockyard_train_position(this.queryParams).then(response => {
        this.stockyard_train_positionList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        deptId: null,
        drawingId: null,
        lineId: null,
        lineCode: null,
        trainModelId: null,
        iconId: null,
        trainStatus: null,
        placement: null,
        trainNumber: null,
        crewId: null,
        crewWorkNumber: null,
        crewName: null,
        confirmerId: null,
        confirmerWorkNumber: null,
        confirmerName: null,
        entryTime: null,
        approvalTime: null,
        estimatedDepartureTime: null,
        currentApproverId: null,
        currentApproverWorkNumber: null,
        currentApproverName: null,
        description: null,
        standardParams: null,
        customParams: null,
        ext: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加整备场火车位置信息"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getStockyard_train_position(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改整备场火车位置信息"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateStockyard_train_position(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addStockyard_train_position(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除整备场火车位置信息编号为"' + ids + '"的数据项？').then(function() {
        return delStockyard_train_position(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/stockyard_train_position/export', {
        ...this.queryParams
      }, `stockyard_train_position_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
